package com.geekhole.demo.app.product;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

import static com.geekhole.demo.app.TimeUtil.sleep;

@Service
public class ProductApplication {
    public Product getById(Long id){
        sleep(20);
        Product product = createProduct(id);
        return product;
    }

    private Product createProduct(Long id) {
        Product product = new Product();
        product.setId(id);
        product.setShowName("新品-" + id);
        return product;
    }

    public List<Product> getByIds(List<Long> ids){
        sleep(50);
        return ids.stream()
                .map(this::createProduct)
                .collect(Collectors.toList());
    }
}
